package com.ruoyi.rabbitmq.domain;

import java.io.Serializable;
import java.util.Date;

/**
 * 消息信息实体
 * 
 * @author ruoyi
 */
public class MessageInfo implements Serializable
{
    private static final long serialVersionUID = 1L;

    /** 消息ID */
    private String messageId;

    /** 消息内容 */
    private Object content;

    /** 消息类型 */
    private String messageType;

    /** 交换机名称 */
    private String exchange;

    /** 路由键 */
    private String routingKey;

    /** 队列名称 */
    private String queueName;

    /** 重试次数 */
    private Integer retryCount;

    /** 最大重试次数 */
    private Integer maxRetryCount;

    /** 创建时间 */
    private Date createTime;

    /** 过期时间 */
    private Date expireTime;

    /** 消息状态 */
    private String status;

    /** 错误信息 */
    private String errorMessage;

    public MessageInfo()
    {
        this.createTime = new Date();
        this.retryCount = 0;
        this.maxRetryCount = 3;
        this.status = "PENDING";
    }

    public MessageInfo(Object content, String messageType, String exchange, String routingKey)
    {
        this();
        this.content = content;
        this.messageType = messageType;
        this.exchange = exchange;
        this.routingKey = routingKey;
    }

    public String getMessageId()
    {
        return messageId;
    }

    public void setMessageId(String messageId)
    {
        this.messageId = messageId;
    }

    public Object getContent()
    {
        return content;
    }

    public void setContent(Object content)
    {
        this.content = content;
    }

    public String getMessageType()
    {
        return messageType;
    }

    public void setMessageType(String messageType)
    {
        this.messageType = messageType;
    }

    public String getExchange()
    {
        return exchange;
    }

    public void setExchange(String exchange)
    {
        this.exchange = exchange;
    }

    public String getRoutingKey()
    {
        return routingKey;
    }

    public void setRoutingKey(String routingKey)
    {
        this.routingKey = routingKey;
    }

    public String getQueueName()
    {
        return queueName;
    }

    public void setQueueName(String queueName)
    {
        this.queueName = queueName;
    }

    public Integer getRetryCount()
    {
        return retryCount;
    }

    public void setRetryCount(Integer retryCount)
    {
        this.retryCount = retryCount;
    }

    public Integer getMaxRetryCount()
    {
        return maxRetryCount;
    }

    public void setMaxRetryCount(Integer maxRetryCount)
    {
        this.maxRetryCount = maxRetryCount;
    }

    public Date getCreateTime()
    {
        return createTime;
    }

    public void setCreateTime(Date createTime)
    {
        this.createTime = createTime;
    }

    public Date getExpireTime()
    {
        return expireTime;
    }

    public void setExpireTime(Date expireTime)
    {
        this.expireTime = expireTime;
    }

    public String getStatus()
    {
        return status;
    }

    public void setStatus(String status)
    {
        this.status = status;
    }

    public String getErrorMessage()
    {
        return errorMessage;
    }

    public void setErrorMessage(String errorMessage)
    {
        this.errorMessage = errorMessage;
    }

    /**
     * 增加重试次数
     */
    public void incrementRetryCount()
    {
        this.retryCount++;
    }

    /**
     * 检查是否超过最大重试次数
     */
    public boolean isMaxRetryExceeded()
    {
        return this.retryCount >= this.maxRetryCount;
    }

    /**
     * 检查消息是否过期
     */
    public boolean isExpired()
    {
        return this.expireTime != null && new Date().after(this.expireTime);
    }

    @Override
    public String toString()
    {
        return "MessageInfo{" +
                "messageId='" + messageId + '\'' +
                ", content=" + content +
                ", messageType='" + messageType + '\'' +
                ", exchange='" + exchange + '\'' +
                ", routingKey='" + routingKey + '\'' +
                ", queueName='" + queueName + '\'' +
                ", retryCount=" + retryCount +
                ", maxRetryCount=" + maxRetryCount +
                ", createTime=" + createTime +
                ", expireTime=" + expireTime +
                ", status='" + status + '\'' +
                ", errorMessage='" + errorMessage + '\'' +
                '}';
    }
} 